﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace EShop.Core.Model.Common
{
    public class EShopEnum
    {
        public enum OrderStateEnum
        {
            /// <summary>
            /// 新订单
            /// </summary>
            [Display(Name="新订单")]
            New=0,
            /// <summary>
            /// 等待广告主确认
            /// </summary>
            [Display(Name="待确认")]
            Affirm=1,
            /// <summary>
            /// 广告主确认通过，在执行中的订单
            /// </summary>
            [Display(Name = "执行中")]
            Execute=2,
            /// <summary>
            /// 提交完成，等待核实的
            /// </summary>
             [Display(Name = "已完成（待审核）")]
            Verify=3,
            /// <summary>
            /// 核实通过，等待买家确认的
            /// </summary>
             [Display(Name = "待买家确认")]
            Ok=4,
            /// <summary>
            /// 等待结算金额
            /// </summary>
             [Display(Name = "结算中")]
            Clearing=5,
            /// <summary>
            /// 在状态1后，被拒绝的订单
            /// </summary>
            [Display(Name = "质检退款")]
             Fail=6,
            /// <summary>
            /// 完成
            /// </summary>
             [Display(Name = "完成")]
            Finish=99

        }
    }

    public static class EnumExtensions
    {
        public static string ToDescription(this Enum e)
        {
            var attributes = (DisplayAttribute[])e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false);
            return attributes.Length > 0 ? attributes[0].Description : string.Empty;
        }

        public static string ToName(this Enum e)
        {
            var attributes = (DisplayAttribute[])e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false);
            return attributes.Length > 0 ? attributes[0].Name : string.Empty;
        }
    }
}
